package com.litchi.tutor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.litchi.tutor.common.entity.Config;
import com.litchi.tutor.mapper.ConfigMapper;
import com.litchi.tutor.service.ConfigService;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author XuRuiPeng
 * @date 2021/10/26 10:57
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {

    /**
     * 从config表中获取value并自增作为userId
     * @param key
     * @return
     */
    @Override
    public String getConfigValueByKey(String key) {
        Config config = this.getOne(new QueryWrapper<Config>().eq("`key`", key));
        String value = config.getValue();
        int i = Integer.parseInt(value);
        Random random = new Random();
        int ran = random.nextInt(10);

        int ranValue = i + ran;
        System.out.println(ranValue);
        return String.valueOf(ranValue);
    }
}
